import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_types.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';

// 积分容器
class XinDongLiaoTianMessageScoreContainer extends StatelessWidget {
  final bool hidden;
  final V2TimMessage message;
  final dynamic score;
  final Widget child;

  const XinDongLiaoTianMessageScoreContainer(
      {super.key, required this.hidden, required this.message, this.score, required this.child});

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        child,
        if (!hidden && XinDongUserController.to.sex == Gender.female)
          Padding(
            padding: const EdgeInsets.only(top: 5),
            child: Text(
              "+${score ?? getScore(message.cloudCustomData)}积分",
              style: const TextStyle(fontSize: 10, color: Colors.red),
            ),
          ),
      ],
    );
  }

  getScore(String? data) {
    if (data == null || !data.contains("score")) return "0";
    Map<String, dynamic> result = json.decode(data);
    return result["score"];
  }
}
